import Vue from 'vue'
import MemberFormDialog from "./MemberFormDialog.vue";

export function showMemberDialog (props) {
    // 创建构造器
    const MemberFormDialogConstructor = Vue.extend(MemberFormDialog);
    // 创建实例
    const instance = new MemberFormDialogConstructor({
        el: document.createElement('div'),
        propsData: props
    });
    
    // 监听提交和取消事件
     instance.$on('submit', () => {
        if (props.onSubmit) {
            props.onSubmit();
        }
        document.body.removeChild(instance.$el);
        instance.$destroy();
    })
    
    instance.$on('cancel', () => {
        if (props.onCancel) {
            props.onCancel();
        }
        document.body.removeChild(instance.$el);
        instance.$destroy();
    })

    // 将实例挂载到 body 上
    document.body.appendChild(instance.$el);
    // 根据会员id获取会员信息
    if (props.memberId) {
        instance.initFormData(props.memberId);
    }
    instance.visible = true;
}